﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using DotNetOpenAuth.OpenId;  
using DotNetOpenAuth.OpenId.RelyingParty;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        OpenIdRelyingParty rp = new OpenIdRelyingParty();
        var r = rp.GetResponse();
        if (r != null)
        {
            switch (r.Status)
            {
                case AuthenticationStatus.Authenticated:
                    Session["GoogleIdentifier"] = r.ClaimedIdentifier.ToString();
                    lblMensaje.Text = "Exito.";
                    Response.Redirect("Consultas.aspx");
                    break;
                case AuthenticationStatus.Canceled:
                    lblMensaje.Text = "Cancelled.";
                    break;
                case AuthenticationStatus.Failed:
                    lblMensaje.Text = "Login Failed.";
                    break;
            }
        } 
    }

    protected void btnLogin_Click(object src, CommandEventArgs e)
    {
        string discoveryUri = e.CommandArgument.ToString();
        OpenIdRelyingParty openid = new OpenIdRelyingParty();
        var b = new UriBuilder(Request.Url) { Query = "" };
        var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri);
        req.RedirectToProvider();
    }  

}
